package com.zxm.sunshineaiary.activity.base;

import android.app.Activity;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.zxm.sunshineaiary.activity.R;
import com.zxm.sunshineaiary.view.mydialog.MyDialog;
import com.zxm.sunshineaiary.view.mydialog.SettingDialog;

public class MybaseActivity extends Activity {

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			new MyDialog(this).show();
			return true;
		}
		return super.onKeyDown(keyCode, event);

	}

	protected void startNextActivity(Class activity) {
		Intent intent = new Intent(this, activity);
		this.startActivity(intent);
		this.finish();
	}

	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case 1:
			new SettingDialog(this).show();
			break;
		case 2:
			Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();
			break;
		}
		return super.onMenuItemSelected(featureId, item);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Toast.makeText(this, "2222", Toast.LENGTH_SHORT).show();
		menu.add(0, 1, 1, "设置");
		menu.add(0, 2, 2, "关于");
		return super.onCreateOptionsMenu(menu);
	}

}
